package com.tyut.listener;

import com.tyut.domain.UserDocument;
import com.tyut.service.SearchService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * 用户索引监听器
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class UserIndexListener {

    private final SearchService searchService;

    /**
     * 监听用户创建/更新消息
     *
     * @param document 用户文档
     */
    @RabbitListener(queues = "user.index.queue")
    public void handleUserIndex(UserDocument document) {
        log.info("收到用户索引消息: {}", document);
        boolean result = searchService.indexUser(document);
        log.info("用户索引结果: {}", result);
    }

    /**
     * 监听用户删除消息
     *
     * @param id 用户ID
     */
    @RabbitListener(queues = "user.delete.queue")
    public void handleUserDelete(Long id) {
        log.info("收到用户删除消息: {}", id);
        boolean result = searchService.deleteUser(id);
        log.info("用户删除结果: {}", result);
    }
} 